const app = getApp()
const { listApi } = require('../../../api/services/Aklink/index')
Page({
  data: {
    params: { pageNum: 0, pageSize: 10, comName: '' },
    dataList: [],
    dataMore: true,
    total: 0,
  },

  // 搜索框
  onChange(e) {
    this.setData({ 'params.comName': e.detail })
  },

  async onSearch() {
    const res = await listApi(this.data.params)
    if (res.code != 200) {
      return app.toast(res.msg)
    }
    const newList = res.rows
    if (newList.length == 0) {
      this.setData({ dataMore: false })
    }
    this.setData({ dataList: newList })
  },

  // 获取数据列表
  async getListData() {
    if (!this.data.dataMore) return
    this.data.params.pageNum++
    const res = await listApi(this.data.params)
    if (res.code != 200) {
      return app.toast(res.msg)
    }
    const newList = [...this.data.dataList, ...res.rows]
    this.setData({
      total: res.total,
      dataList: newList,
      dataMore: newList.length < res.total,
    })
  },

  //企业详情
  handleInfo(event) {
    let { comid } = event.currentTarget.dataset
    wx.navigateTo({ url: '/pages/businessArchives/businessInfo/businessInfo?comid=' + comid })
  },

  onLoad: function () {
    this.getListData()
  },

  onReachBottom: function () {
    this.getListData()
  },
})
